<?php

namespace app\web\controller;
use app\admin\model\Member as MemberModel;
use app\adminmall\model\ConsMemberModel;
use app\adminmall\model\LineMemberModel;
use app\common\controller\StoreBaseController;
use think\Db;
/**
 * 商家会员统计
 */
class MemberEnterController extends StoreBaseController
{
 	protected $member_model;
	protected $consmember_model;
	protected $linemember_model;
	
    protected function _initialize() {
        parent::_initialize();
        $this->member_model = new MemberModel();
		$this->consmember_model = new ConsMemberModel();
		$this->linemember_model = new LineMemberModel();
    }
    /**
     * 会员统计
     * @author [lx] 
     */
    public function index( $page = 1){
		$agent_id = session('storeInfo')['id'];
		$u_id = session('storeInfo')['u_id'];
		//七天前判断
		$now = date('Y-m-d');
		$befor=date('Y-m-d',strtotime('-7 day'));
		//近七日的每日会员统计
		 $today=[];
        for($i=0;$i<7;$i++){
        	$time=date('Y-m-d',strtotime(-$i.'day'));
      		$today[$i] = Db::name("mall_consmember")->where('agent_id',$agent_id)
      		->where('time',$time)->count('id');
		}

		$this->assign('list',$today);
		//近七日的每日线下会员统计
		$line=[];
        for($i=0;$i<7;$i++){
        	$time=date('Y-m-d',strtotime(-$i.'day'));
       		$where['reg_date']=['like','%'.$time.'%'];
      		$line[$i] = Db::name("line_member")->where('store_id',$agent_id)
      		->where($where)->count('id');
		}
		$this->assign('line',$line);
		//线上会员统计
		$conslist = Db::name("mall_consmember")->where('agent_id',$agent_id)->count('id');
		$this->assign('conslist',$conslist);
		
		//线下会员统计
		$linelist = Db::name("line_member")->where('store_id',$agent_id)->count('id');
		$this->assign('linelist',$linelist);
		
		//下级会员统计
		$param['uid'] = $u_id;
		$param['level'] = '1';
		$branchlist = Db::name("mall_level")->where($param)->count('id');
        $this->assign('branchlist',$branchlist);

        return $this->fetch();
    }


   
}